home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
LANG
/
C
/
LIB
/
HASWIN
/
HASWIN3
/
_files
/
_haswin
/
TOFILER._c
< prev
next >
Wrap
Text File
|
1991-05-27
|
8KB
|
202 lines
/* > $.CLIB.C.tofiler
*
* HASWIN Graphics Library
* =========================
*
* Copyright (C) H.A.Shaw 1990.
* Howard A. Shaw.
* The Unit for Space Sciences,
* Room 165,
* Physics Building,
* University of Kent at Canterbury.
* Canterbury.
* Kent. CT2 7NJ
* You may use and distribute this code freely, however please leave
* it alone. If you find bugs (and there will be many) please contact
* me and the master source can be modified. If you keep me informed
* of who you give copies of this to then I can get release upgrades
* to them.
*
* These routines communicate with the Filer. This was supposed to be
* a file full of inter-process routines, but it never came off. I
* hope to get it all done properly in the next release.
*
* So far these routines are only to support the thing Acorn wants
* about closing a window with the adjust button. It might seem like
* a good idea, but the code to do it with the proper defaults is a
* pain in the bum. Luckily we don't often have to do this.
*/
#include "includes.h"
/*
* this piece of code sends the message "msg" to the filer giving the
* full file spec of the file "fname" in the filesystem "fsys".
* "msg" must either be MESSAGE_FilerOpenDir or MESSAGE_FilerCloseDir.
* It has to create a full filespec, which is not easy!!
*/
static int haswin_send_to_filer(char *fs, char *fname, int msg) {
register char *ptr;
register int i;
char dname[64], cdir[64], fsys[64], *realname;
int fsysnum, oldfsysnum;
buffer pbuf;
_kernel_swi_regs regs;
if ((msg != MESSAGE_FilerCloseDir) && (msg != MESSAGE_FilerOpenDir))
return(HASWIN_FALSE);
/*
* find the filesystem number. Scan fname looking for ":"
* NB: If ':' is first character then use default filesystem and
* take ':' as discname starter.
* Can't have ':' except as filesystem separator.
*/
realname = fname;
strcpy(fsys, fs);
for (ptr=fname+1; *ptr; ptr++) {
if (*ptr == ':') {
*ptr = '\0';
strcpy(fsys, fname);
*ptr = ':';
fname = ptr+1;
break;
} else if ((*ptr == '.') || (*ptr == '$'))
break;
}
regs.r[0] = 13;
regs.r[1] = (int)fsys;
regs.r[2] = 0;
if ((!haswin_swi(OS_FSControl, ®s)) || (!regs.r[2])) {
haswin_interrorprintf("filing system %s not available, cannot access filer for file %s", fsys, realname);
return(HASWIN_FALSE);
}
fsysnum = regs.r[1];
/*
* change the current filesystem, so we can do proper discname
* and current directory lookups. This is a *REAL* pain!!
*
* 1) use OS_FSControl to set temp fsys to current fsys
* 2) use OS_Args to read temp fsys number
* 3) use OS_FSControl to change current and temp fsys
* 4) ... do processing ...
* 5) remember to use OS_FSControl to reset current and temp fsys
* 6) leave routine.
*/
regs.r[0] = 19;
haswin_swi(OS_FSControl, ®s);
regs.r[0] = 0;
regs.r[1] = 0;
haswin_swi(OS_Args, ®s);
oldfsysnum = regs.r[0];
regs.r[0] = 14;
regs.r[1] = (int)fsys;
haswin_swi(OS_FSControl, ®s);
/*
* now find the disc name. It starts ":" and ends ".".
* If we don't find a name, do a OS_GBPB number 5 to get it.
*/
if (*fname == ':') {
fname++;
for (ptr=fname; *ptr; ptr++) {
if (*ptr == '.') {
*ptr = '\0';
strcpy(dname, fname);
*ptr = '.';
fname = ptr+1;
break;
}
}
} else {
regs.r[0] = 5;
regs.r[2] = (int)&pbuf;
haswin_swi(OS_GBPB, ®s);
pbuf.c[pbuf.c[0]+1] = '\0';
if (!strncmp(&pbuf.c[1], "\"Unset\"", 7))
strcpy(dname, "");
else
strcpy(dname, &pbuf.c[1]);
}
if (*fname != '$') {
/* file must be relative to current dir */
regs.r[0] = 6;
regs.r[2] = (int)&pbuf;
haswin_swi(OS_GBPB, ®s);
pbuf.c[pbuf.c[1]+2] = '\0';
strcpy(cdir, &pbuf.c[2]);
} else
*cdir = '\0';
/*
* create the message buffer
*/
pbuf.i[3] = 0;
pbuf.i[4] = msg;
pbuf.i[5] = fsysnum;
pbuf.i[6] = 0;
if (*cdir) {
if (!strncmp(cdir, "\"Unset\"", 7))
strcpy(cdir, "$");
sprintf(&pbuf.c[28], "%s::%s.%s.%s",fsys,dname,cdir,fname);
} else
sprintf(&pbuf.c[28], "%s::%s.%s", fsys,dname, fname);
/*
* now look at the filename given, and remove leaves until
* we get a real directory.
*/
do {
regs.r[0] = 17;
regs.r[1] = (int)(&pbuf.c[28]);
haswin_swi(OS_File, ®s);
switch (regs.r[0]) {
case 2:
/* a directory, what we want */
break;
case 1:
/* a file, so scan back leafname and remove */
i = asciilen(&pbuf.c[28]);
while ((i>0) && (pbuf.c[28+i] != '.'))
i--;
if (i == 0) {
haswin_interrorprintf("cannot find file %s (%s) in filesystem %s", realname, &pbuf.c[28], fsys);
regs.r[0] = 14;
regs.r[1] = oldfsysnum;
haswin_swi(OS_FSControl, ®s);
return(HASWIN_FALSE);
}
pbuf.c[28+i] = '\0';
break;
default:
/* does not exist, so error */
haswin_interrorprintf("file %s (%s) does not exist in filesystem %s", realname, &pbuf.c[28], fsys);
regs.r[0] = 14;
regs.r[1] = oldfsysnum;
haswin_swi(OS_FSControl, ®s);
return(HASWIN_FALSE);
}
} while (regs.r[0] != 2);
pbuf.i[0] = 28 + ((asciilen(&pbuf.c[28])+4) & 0xFFFFFFFC);
/*
* finally send the message to the filer
*/
regs.r[0] = 17;
regs.r[1] = (int)&pbuf;
regs.r[2] = 0;
haswin_swi(HASWIN_Send_message, ®s);
regs.r[0] = 14;
regs.r[1] = oldfsysnum;
haswin_swi(OS_FSControl, ®s);
return(HASWIN_TRUE);
}
int haswin_openfiler(char *fsys, char *fname) {
return(haswin_send_to_filer(fsys, fname, MESSAGE_FilerOpenDir));
}
int haswin_closefiler(char *fsys, char *fname) {
return(haswin_send_to_filer(fsys, fname, MESSAGE_FilerCloseDir));
}